<template>
  <div
    class="container"
    element-loading-background="transparent"
    v-loading="loading"
  >
    <div v-if="tabList" class="content-wrap">
      <div class="item-wrap one">
        <div class="item">
          <span>交易单量（笔）</span>
          <span>{{ tabList.jyb }}</span>
        </div>
        <div class="item">
          <span>交易重量（KG）</span>
          <span>{{ tabList.jyl }}</span>
        </div>
        <div class="item">
          <span>交易额（元）</span>
          <span>{{ tabList.jye }}</span>
        </div>
      </div>
      <div class="item-wrap two">
        <div class="item">
          <span>今日检测批次</span>
          <span>{{ tabList.brjcpc }}</span>
        </div>
        <div class="item">
          <span>今日合格率</span>
          <span>{{ tabList.brjchegelv + "%" }}</span>
        </div>
        <div class="item">
          <span>当月检测总批次</span>
          <span>{{ tabList.byjcpc }}</span>
        </div>
      </div>
      <div class="three">
        <div class="big-item">
          <span>今日交易占比图</span>
          <div class="left-echart" id="left-echart"></div>
        </div>
        <div class="big-item">
          <span>检测项目占比图</span>
          <div class="right-echart" id="right-echart"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref,onUnmounted } from "vue";
import {
  getCXGSByMarket,
  getJYCX,
  getTJXX,
  getJRJY,
  getXMJC,
} from "@/apis/subjectInfo";
import { useRouter } from "vue-router";
const boyUrl = ref("src/assets/images/ztxx/boy.png");
const girlUrl = ref("src/assets/images/ztxx/girl.png");
let loading = ref(false);
const router = useRouter();
const tabList = ref();
const option = ref();
const option1 = ref();
const getInfo = async () => {
  loading.value = true;
  await getTJXX().then((res) => {
    tabList.value = res.data;
    loading.value = false;
  });
  await getDayInfo();
  await getProject();
};
getInfo();
//获取今日交易图
const getDayInfo = async () => {
  let res = await getJRJY();
  let valueList = [];
  res.data.forEach((item) => {
    valueList.push({ value: item.jrjybilv, name: item.splb });
  });
  option.value = {
    tooltip: {
      trigger: "item",
      formatter: function (params) {
        // 提示框浮层内容格式器
        return params.name + "<br/>" + params.value + "%";
      },
    },
    legend: {
      orient: "vertical",
      right: "10%",
      top: "15%",
      itemGap: 5, // 图例项之间的距离
      itemHeight: 6, // 图例项的高度
      itemWidth: 6,
      textStyle: {
        color: "#333", // 文本颜色
        fontSize: 9, // 文本大小
        fontFamily: "Arial", // 文本字体
      },
    },
    series: [
      {
        type: "pie",
        radius: "70%",
        padAngle: 5,
        data: valueList,
        label: {
          normal: {
            show: true,
            position: "inside",
            formatter: "{d}%",
            textStyle: {
              align: "center",
              baseline: "middle",
              fontSize: 8,
              color: "#fff",
            },
          },
        },
        labelLine: {
          show: false,
        },
        center: ["24%", "50%"], //饼图的位置
      },
    ],
  };
  echarts.init(document.getElementById("left-echart")).dispose()
  var chartDom = document.getElementById("left-echart");
  var myChart = echarts.init(chartDom);
  myChart.setOption(option.value);
};
//获取项目占比图
const getProject = async () => {
  let res = await getXMJC();
  let valueList = [];
  res.data.forEach((item) => {
    valueList.push({ value: item.bilv, name: item.jcxm });
  });
  option1.value = {
    tooltip: {
      trigger: "item",
      formatter: function (params) {
        // 提示框浮层内容格式器
        return params.name + "<br/>" + params.value + "%";
      },
    },
    legend: {
      orient: "vertical",
      right: "0%",
      top: "15%",
      itemGap: 5, // 图例项之间的距离
      itemHeight: 6, // 图例项的高度
      itemWidth: 6,
      textStyle: {
        color: "#333", // 文本颜色
        fontSize: 9, // 文本大小
        fontFamily: "Arial", // 文本字体
      },
    },
    series: [
      {
        type: "pie",
        radius: "70%",
        padAngle: 5,
        data: valueList,
        label: {
          normal: {
            show: true,
            position: "inside",
            formatter: "{d}%",
            textStyle: {
              align: "center",
              baseline: "middle",
              fontSize: 7,
              color: "#fff",
            },
          },
        },
        labelLine: {
          show: false,
        },
        center: ["24%", "50%"], //饼图的位置
      },
    ],
  };
  echarts.init(document.getElementById("right-echart")).dispose()
  var chartDom = document.getElementById("right-echart");
  var myChart = echarts.init(chartDom);
  myChart.setOption(option1.value);
};

</script>
<style lang="scss" scoped>
.container {
  height: 100%;
  .content-wrap {
    padding: 0 5px;
    padding-top: 20px;
    height: 420px;
    .item-wrap {
      display: flex;
      justify-content: space-between;
      display: grid;
      grid-row-gap: 2px;
      justify-content: space-around;
      align-content: center;
      grid-template-columns: repeat(auto-fill, 162px);
      .item {
        // width: 140px;
        // height: 70px;
        letter-spacing: 1px;
        padding: 10px 15px;
        border: 1px solid #333;
        border-radius: 10px;
        span {
          display: inline-block;
          &:nth-child(1) {
            font-family: SourceHanSansCN, SourceHanSansCN;
            font-weight: bold;
            font-size: 13px;
            color: #ffffff;
          }
          &:nth-child(2) {
            width: 100%;
            text-align: center;
            font-family: Bahnschrift, Bahnschrift;
            font-weight: 600;
            font-size: 28px;
            color: #ffffff;
          }
        }
      }
    }
    .one {
      .item {
        &:nth-child(1) {
          background: #aeca63;
        }
        &:nth-child(2) {
          background: #88d3c8;
        }
        &:nth-child(3) {
          background: #f7bf72;
        }
      }
    }
    .two {
      margin-top: 20px;
      .item {
        &:nth-child(1) {
          background: #fe8255;
        }
        &:nth-child(2) {
          background: #c969a6;
        }
        &:nth-child(3) {
          background: #2d8dec;
        }
      }
    }
    .three {
      margin-top: 20px;
      height: 159px;
      display: flex;
      justify-content: space-between;
      display: grid;
      grid-row-gap: 2px;
      justify-content: space-around;
      align-content: center;
      grid-template-columns: repeat(auto-fill, 244px);
      .big-item {
        // width: 220px;
        // height: 180px;
        letter-spacing: 1px;
        padding: 10px 15px;
        background: #fff;
        border-radius: 10px;
        span {
          font-family: SourceHanSansCN, SourceHanSansCN;
          font-weight: bold;
          font-size: 16px;
          color: #103b97;
        }
        .left-echart {
          width: 190px;
          height: 110px;
        }
        .right-echart {
          width: 190px;
          height: 110px;
        }
      }
    }
  }
}
</style>
